// 搜索框
$("#otxt").on("input", function () {
    $.ajax({
        url: "https://suggest.taobao.com/sug?",

        data: {
            code: "utf-8",
            q: $(this).val(),
            bucketid: "atb_search"
        },
        success: res => {
            let str = "";
            res.result.forEach(val => {
                str += `<li>${val[0]}</li>`
                console.log(val[0]);
            })
            $(".olist").html(str)
        },
        dataType: "jsonp"
    })
})
var otxt = document.querySelector("#otxt");
var olist = document.querySelector(".olist")
var ali = olist.querySelectorAll(".olist>li");
var index = 0;
var keyState = 0;


otxt.oninput = function () {
    if (otxt.value === "") {
        olist.style.display = "none"
    } else {
        olist.style.display = "block"
    }
}


$(".olist").on("click", "li", function () {
    otxt.value = this.innerHTML
    olist.style.display = "none"

})
document.onclick = function () {
    olist.style.display = "none"

}


